package dk.pun.aot.client.widget;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class ConfirmDialog extends DialogBox {

	private static ConfirmDialogUiBinder uiBinder = GWT.create(ConfirmDialogUiBinder.class);

	interface ConfirmDialogUiBinder extends UiBinder<Widget, ConfirmDialog> {}

	@UiField Label label;
	@UiField Button okButton;
	@UiField Button cancelButton;
	
	private Command command;
	
	public ConfirmDialog(String message, Command command) {
		setWidget(uiBinder.createAndBindUi(this));
		setText("Confirm");
		setAutoHideEnabled(false);
		setGlassEnabled(true);
		
		this.command = command;
		this.label.setText(message);
	}

	@UiHandler("okButton")
	public void okButtonClicked(ClickEvent event) {
		this.command.execute();
		this.hide();
	}
	
	@UiHandler("cancelButton")
	public void cancelButtonClicked(ClickEvent event) {
		this.hide();
	}
	
}
